Next | Prev | Up | Top | Contents | Index
Creating a Real-time File
You can only request a guaranteed rate from a real-time disk file. A real-time disk file is identified by the fact that it is stored within the real-time subvolume of an XFS logical volume.
The file management information for all files in a volume (the directories as well as XFS management records) are stored in the data subvolume. A real-time subvolume contains only the data of real-time files. A real-time subvolume comprises an entire disk device or partition and uses a separate SCSI controller from the data subvolume. Because of these constraints, the GRIO facility can predict the data rate at which it can transfer the data of a real-time file.
You create a real-time file in the following steps, which are illustrated in Example 8-4.
- Open the file with the options O_CREAT, O_EXCL, and O_DIRECT. That is, the file must not exist at this point, and must be opened for direct I/O (see "Using Direct I/O").
- Modify the file descriptor to set its extent size, which is the minimum amount by which the file will be extended when new space is allocated to it, and also to establish that the new file is a real-time file. This is done using fcntl() with the FS_FSSETXATTR command. Check the value returned by fcntl() as several errors can be detected at this point.
The extent size must be chosen to match the characteristics of the disk; for example it might be the "stripe width" of a striped disk.
- Write any amount of data to the new file. Space will be allocated in the real-time subvolume instead of the data subvolume because of step (2). Check the result of the first write() call carefully, since this is another point at which errors could be detected.
Once created, you can read and write a real-time file the same as any other file, except that it must always be opened with O_DIRECT. You can use a real-time file with asynchronous I/O, provided it is not under a guarantee (see "Sharing Access to Guaranteed Files").
Example 8-4 : Function to create a real-time file
#include <sys/fcntl.h>
#include <sys/fs/xfs_itable.h>
int createRealTimeFile(char *path, __uint32_t esize)
{
struct fsxattr attr;
bzero((void*)&attr,sizeof(attr));
attr.fsx_xflags = XFS_XFLAG_REALTIME;
attr.fsx_extsize = esize;
int rtfd = open(path, O_CREAT + O_EXCL + O_DIRECT );
if (-1 == rtfd)
{perror("open new file"); return -1; }
if (-1 == fcntl(rtfd, F_FSSETXATTR, &attr) )
{perror("fcntl set rt & extent"); return -1; }
return rtfd; /* first write to it creates file*/
}
Next | Prev | Up | Top | Contents | Index